﻿function CopyToClipboard(txt){
	netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
	var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
	var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
	var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
	str.data = txt;
	trans.setTransferData("text/unicode",str,txt.length*2);
	
	var clipid=Components.interfaces.nsIClipboard;
	clip.setData(trans,null,clipid.kGlobalClipboard); 
}

function Now(){
	var _now = new Date();
	//alert(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds());
	return getUnixTime(_now.getFullYear(),_now.getMonth(),_now.getDate(),_now.getHours(),_now.getMinutes(), _now.getSeconds());
}
function getUnixTime(year,month,day,hour,minute,second){
	year = parseInt(year)?parseInt(year):1970;
	month = parseInt(month)?parseInt(month):0;
	if(month>0){month=month-1}
	day = parseInt(day)?parseInt(day):1;
	hour = parseInt(hour)?parseInt(hour):0;
	minute = parseInt(minute)?parseInt(minute):0;
	second = parseInt(second)?parseInt(second):0;
	
	//alert(year+"-"+month+"-"+day+"-"+hour+"-"+minute+"-"+second);
	
	var d = new Date(Date.UTC(year,month,day,hour,minute,second));
	return d.getTime();
}
function inic(){
	inicOptions();
	setContainerSize();
	setMainMenu();
	window.onresize = setContainerSize;
	window.defaultStatus = "Yellow Pages Co. ®";
}
function _escape(str){
	str = escape(str);
	var reserved = Array("$","&","+",",","/",":",";","=","?","@");
	var replaces = Array("24","26","2B","2C","2F","3A","3B","3D","3F","40");
	for(var i=0; i<reserved.length; i++){
		str = str.replace(reserved[i],'%'+replaces[i]);
	}
	return str;
}
function trim(str){
	if(typeof(str) == "string")
		return str.replace(/^\s+|\s+$/,'');
	else
		return "";
}
function disableTAB(obj,e){
	kc=e.keyCode; 
	var ret=false;
	if(kc==9){
		var start = obj.selectionStart;
		var end = obj.selectionEnd;
		
		var tab = "\t";
		obj.value = obj.value.substr(0,start)+tab+obj.value.substr(end);
		obj.focus();
		var pos = start+tab.length;
		obj.setSelectionRange(pos,pos);
		ret=true;
	}
	return ret;
}
function removeFromParent(obj){
	if(obj.parentNode){
		if(confirm('Da li ste sigurni u vezi brisanja?')){
			obj.parentNode.removeChild(obj);
		}
	}
}
function setMainMenu(){
	var mm = document.getElementById("main_menu");
	if(!mm)
		return;
	var as = mm.getElementsByTagName("a");
	var oc = null;
	var tmp = null;
	for(var i=0; i<as.length; i++){
		if(as[i].onclick){
			oc = as[i].onclick;
			oc = oc.toString();
			var tmp = oc.split("}");
			tmp = tmp[0].split("{");
			tmp = tmp[1];
			tmp += "hideMainMenu(this.parentNode.parentNode);"
			tmp += "\nthis.parentNode.parentNode.parentNode.onmouseover = function(){var ul=this.getElementsByTagName('ul')[0]; if(ul){ul.style.display='block'; ul._over=true;}}";
			tmp += "\nthis.parentNode.parentNode.parentNode.onmouseout = function(){var ul=this.getElementsByTagName('ul')[0]; if(ul){hideMainMenu(ul);ul._over=false;}}";
			as[i].toonclick = tmp;
			as[i].onclick = function(event){
				eval(this.toonclick);
			}
		}
	}
}
function hideMainMenu(obj){
	obj.style.display='none';
	//obj._to = setTimeout(function(){_HideIt(obj);},3000);
	//_HideIt(obj);
}
function _HideIt(obj){
	if(!obj._over){
		obj.style.display="none";
	}
}
function setContainerSize(){
	var container 	= document.getElementById("container");
	var mmenu		= document.getElementById("main_menu");
	if(!container)
		return;
	
	var w_height	= window.innerHeight+document.body.scrollTop;
	var w_width		= window.innerWidth+document.body.scrollLeft;
	
	if(mmenu)
		var mm_height 	= mmenu.offsetHeight;
	else
		var mm_height	= 0;
	
	
	var c_pad_top = 10;
	var c_pad_left = 10;
	
	container.style.height = (w_height-mm_height-(2*c_pad_top)) + "px";
	container.style.width  = (w_width-(2*c_pad_left))+"px";

	var dark = document.getElementById("darkDIV");
	var main = document.getElementById("mainDIV");
	if(dark){
		dark.style.width = window.innerWidth+"px";
		dark.style.height = window.innerHeight+"px";
		if(main){
			var w=main.offsetWidth;
			var h=main.offsetHeight;
			main.style.left = (window.innerWidth>w)?Math.round((window.innerWidth-w)/2)+"px":"10px";
			main.style.top = (window.innerHeight>h)?Math.round((window.innerHeight-h)/2)+"px":"10px";
		}
	}
}
function inicOptions(){
	var desktop_logo = getCookie("desktop_logo");
}
function upperCase(obj){
	obj.value = obj.value.toUpperCase();
}
function blankTarget(f){
	var forma = document.createElement("form");
	forma.action = location.href;
	forma.method = "POST";
	forma.target = "_blank";
	
	var func = document.createElement("input");
	func.name = "func";
	func.type = "hidden";
	func.value = f;
	forma.appendChild(func);
	document.body.appendChild(forma);
	forma.submit();
}
function LoadRSDoc(url, func, action, tip, method) {
	var xmlhttp;
	var start_time=Now();
	switch(method){
		default:
		case 0:
			method = "GET";
			break;
		case 1:
			method = "POST";
			break;
	}
	getXmlObj(url);
	function getXmlObj(url) {
		if (window.XMLHttpRequest) {
	  		xmlhttp=new XMLHttpRequest()
	  	}else if (window.ActiveXObject){
	  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  	}
	  	if (xmlhttp) {
	  		xmlhttp.onreadystatechange=xmlhttpChange
			xmlhttp.onprogress=xmlhttpProgress
	  		if (action) {
				xmlhttp.open(method, url, true);
				if(tip==3){
					xmlhttp.setRequestHeader('Content-Type', 'multipart/form-data');
				}else{
					xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset:utf-8');
				}
				xmlhttp.send(action);
	  		}else{
	  			xmlhttp.open(method,url,true);
	  			xmlhttp.send(null);
	  		}
	  	}
  	}
	function xmlhttpChange() {
		switch (xmlhttp.readyState) {
			case 0:
			case 1:
			case 2:
			case 3:
				if(func != "simpleInject"){
					var throb = document.getElementById("throbber");
					throb.style.left = Math.round((window.innerWidth-throb.offsetWidth)/2)+"px";
					throb.style.top = Math.round((window.innerHeight-throb.offsetHeight)/2)+"px";
					throb.style.display = "block";
				}else{
					if(action){
						if(typeof(action.innerHTML) != "undefined")
							action.innerHTML = "<span class=\"injectThrobber\">Učitavam...</span>"; 
					}else{
						window.status = "Molim sačekajte...";
					}
				}
				break;
			case 4:
				document.getElementById("throbber").style.display = "none";
				var vrati;
				if (tip == 'xml') {
					vrati = xmlhttp.responseXML;
				}else{
					vrati = xmlhttp.responseText;
				}
				if (xmlhttp.status==200){
					var n = Now();
					window.status = "Done in "+((n-start_time)/1000)+" sec.";
					if(func == "simpleInject"){
						if(typeof(action.innerHTML) != "undefined"){
							action.innerHTML = vrati;
						}else{
							alert(vrati);
						}
					}else{
						var tmp = func.split("(");
						func = tmp[0];
						if(tmp.length > 1){
							tmp = tmp[1];
							tmp = tmp.split(")");
							var params = tmp[0];
							if(params){
								eval(func+"(vrati,"+params+");");
							}else{
								eval(func+"(vrati);");
							}
						}else{
							eval(func+"(vrati);");
						}
					}
				}else{
					var errormsg = "";
					if(xmlhttp.status==500){
						errormsg = "Zatražili ste količinu podataka koju server nije u mogućnosti da Vam dostavi ili je došlo do neke greške na serveru.\n";
						errormsg += "Pokušajte ponovo. Ukoliko se problem opet javi, kontaktirajte administratora.";
					}else{
						errormsg = "Javio se problem prilikom dovlacenja podataka.\n";
						errormsg += xmlhttp.status+" - "+xmlhttp.statusText;
						errormsg += "\n\nRequest:\n"+url;
						if(action){
							errormsg += action;
						}
					}
					alert(errormsg);
				}
			break;
		}
	}
	function xmlhttpProgress(e){
		//var perc=Math.round(e.position/e.totalSize*100);
		//window.status = perc+"%";
	}
}
function setContent(content){
	var container = document.getElementById("container");
	pushHistory(container.innerHTML);
	pushHistory(content);
	container.innerHTML = null;
	container.innerHTML = content;
	if(content.match(/<script/)){
		var scripts = container.getElementsByTagName("script");
		var forEval="";
		var forIncl=Array();
		for(var i=0; i<scripts.length; i++){
			var s = scripts[i];
			var lang = s.attributes['language'];
			if((lang && (lang.value.toLowerCase().indexOf("javascript")>=0)) || !lang){
				forEval += "\n"+s.innerHTML;
			}
		}
		eval(forEval);
	}
}
function showThrobber(){
	var t = document.getElementById("throbber");
	if(t)
		t.style.display = "block";
}
function hideThrobber(){
	var t = document.getElementById("throbber");
	if(t)
		t.style.display = "none";
}
function pushHistory(cont){
	var l;
	var h = document.getElementById("history");
	var btn_back = document.getElementById("history_back");
	var btn_forward = document.getElementById("history_forward");
	var exist = inHistory(cont);
	if(h && exist===false){
		var lis = h.childNodes;
		if(lis){
			l = lis.length;
		}else{
			l=0;
		}
		l++;
		if(l>5){
			h.removeChild(lis[0]);
		}
		var li = document.createElement("li");
		li.innerHTML = cont;
		li.id = l;
		h.setAttribute("pointer",l-1);
		h.appendChild(li);
		btn_back.disabled = false;
	}
}
function historyShow(){
	var h = document.getElementById("history");
	if(h){
		var l = h.childNodes.length;
		var a = h.getAttribute("pointer");
		alert(a)
		for(var i=0; i<l; i++){
			alert(i+"\n\n"+h.childNodes[i].innerHTML);
		}
	}
}
function historyBack(){
	var h = document.getElementById("history");
	var c = document.getElementById("container");
	var btn_back = document.getElementById("history_back");
	var btn_forward = document.getElementById("history_forward");
	if(h){
		var a = parseInt(h.getAttribute("pointer"));
		if(a>0){
			var li = h.childNodes[a-1];
			c.innerHTML = h.childNodes[a-1].innerHTML;
			h.setAttribute("pointer",a-1);
			if(a==1){
				btn_back.disabled=true;
			}else{
				btn_back.disabled=false;
			}
			btn_forward.disabled=false;
		}
	}
}
function historyForward(){
	var h = document.getElementById("history");
	var c = document.getElementById("container");
	var btn_back = document.getElementById("history_back");
	var btn_forward = document.getElementById("history_forward");
	if(h){
		var a = parseInt(h.getAttribute("pointer"));
		if(a < (h.childNodes.length-1)){
			var li = h.childNodes[a+1];
			c.innerHTML = h.childNodes[a+1].innerHTML;
			h.setAttribute("pointer",a+1);
		}
		if(a==(h.childNodes.length-2)){
				btn_forward.disabled=true;
			}else{
				btn_forward.disabled=false;
			}
			btn_back.disabled=false;
	}
}
function inHistory(cont){
	var h = document.getElementById("history");
	var state = false;
	if(h){
		var lis = h.childNodes;
		for(var i=0; i<lis.length; i++){
			if(lis[i].innerHTML == cont){
				state=i;
				break;
			}
		}
	}
	return state;
}
function QuickSearch(url,obj,resultObjID1,resultObjID2){
	if(obj.value.length>2){
		url += "&kword="+escape(trim(obj.value));
		url += "&resultObjID1="+resultObjID1;
		url += "&resultObjID2="+resultObjID2;
		LoadRSDoc(url,"AfterQuickSearch('"+obj.id+"')");
	}
}
function AfterQuickSearch(response,objid){
	var obj = document.getElementById(objid);
	if(obj){
		var tmp = response.split("{!}",2);
		var found = parseInt(tmp[0]);
		var listContent = tmp[1];
		if(found>0){
			var listname = "YPQS"+objid;
			var list = document.getElementById(listname);
			if(!list){
				list = document.createElement("div");
				list.id = listname;
				list.className = "YPQuickSearchList";
				list.style.marginLeft = obj.offsetLeft+"px";
				list.style.marginTop = obj.offsetHeight+"px";
				list.onclick = function(){
					this.parentNode.removeChild(this);
				}
				obj.parentNode.insertBefore(list,obj.nextSibling);
			}
			list.innerHTML = listContent;
		}
	}
}
function showAboutYP(str){
	var w=300;
	var h=500;
	if(str){
		var ww = (window.innerWidth>w)?window.innerWidth:(w+10);
		var wh = (window.innerHeight>h)?window.innerHeight:(h+10);
		
		var divDark = document.createElement("div");
		var divMain = document.createElement("div");
		var bs = document.createElement("div");
		var rs = document.createElement("div");
		divDark.id = "darkDIV";
		divDark.style.width = window.innerWidth+"px";
		divDark.style.height = window.innerHeight+"px";
		
		window.onscroll = function(e){
			document.getElementById("darkDIV").style.top = e.target.scrollTop+"px";
		}
		
		divMain.id = "mainDIV";
		divMain.innerHTML = str;
		divMain.style.left = Math.round((ww-w)/2)+"px";
		divMain.style.top = Math.round((wh-h)/2)+"px";
		
		bs.id="shadow_bottom";
		bs.style.width = w+19+"px";
		//bs.style.background="#F00";
		bs.innerHTML = '<img src="gui/shadow_bl.png" alt="" width="7" height="7" border="0" />';
		bs.innerHTML += '<img src="gui/shadow_b.png" alt="" width="'+(w+5)+'" height="7" border="0" />';
		bs.innerHTML += '<img src="gui/shadow_br.png" alt="" width="7" height="7" border="0" />';
		bs.style.top = h+22+"px";
		bs.style.left = 10+"px";
		
		rs.id="shadow_right";
		//rs.style.background="#00F";
		rs.style.width="7px";
		rs.style.height=h+12+"px";
		rs.style.left = w+22+"px";
		rs.style.top = 10+"px";
		rs.innerHTML = '<img src="gui/shadow_tr.png" alt="" width="7" height="7" border="0" />';
		rs.innerHTML += '<img src="gui/shadow_r.png" alt="" width="7" height="'+(h+5)+'" border="0" />';
		
		document.body.appendChild(divDark);
		document.body.appendChild(divMain);
		divMain.appendChild(bs);
		divMain.appendChild(rs);
		showInAboutMain();
	}else{	
		LoadRSDoc('index.php?a=about','showAboutYP');
	}
}
function showInAboutMain(){
	var divMain = document.getElementById("mainDIV");
	var op1 = divMain.style.MozOpacity?parseFloat(divMain.style.MozOpacity):0;
	
	if(op1<1){
		op1 = op1 + 0.1;
		divMain.style.MozOpacity = op1;
		to = setTimeout("showInAboutMain()",10);
	}
}
function hideAbout(){
	var dd = document.getElementById("darkDIV");
	var md = document.getElementById("mainDIV");
	var op1 = md.style.MozOpacity?parseFloat(md.style.MozOpacity):1;
	if(op1>0){
		md.style.MozOpacity = op1 - 0.1;
		setTimeout("hideAbout()",10);
	}else{
		document.body.removeChild(md);
		document.body.removeChild(dd);
	}
}
function login(forma){
	var username = forma.username.value;
	var password = forma.password.value;
	//alert(username+"-"+password)
	action = "a=login&user="+username+"&pass="+password;
	LoadRSDoc("index.php","redirect",action,"",1);
}
function testCapsLock(e,html_obj,position){
	var kc = e.keyCode?e.keyCode:e.charCode;
	var sk = e.shiftKey;
	
	var cl1 = kc >= 65 && kc <= 90 && !sk;
	var cl2 = kc >= 97 && kc <= 122 && sk;
	
	var indicator = document.getElementById("capsLockIndicator");
	if(!indicator){
		var indicator = document.createElement("div");
		indicator.id = "capsLockIndicator";
		indicator.innerHTML = "&lt;CapsLock&gt;";
		
		switch(position){
			case "bottom":
				indicator.style.top = html_obj.offsetTop+html_obj.offsetHeight+"px";
				indicator.style.left = html_obj.offsetLeft+"px";
				break;
			case "right":
				indicator.style.top = html_obj.offsetTop+"px";
				indicator.style.left = html_obj.offsetLeft+html_obj.offsetWidth+"px";
				break;
		}
		
		html_obj.parentNode.appendChild(indicator);
	}
	
	if(cl1 || cl2){ // is <CapsLock>
		// yes
		indicator.style.display = "block";
	}else{
		// no
		indicator.style.display = "none";
	}
}
function logout(){
	LoadRSDoc("index.php?a=logout","redirect");
}
function redirect(url){
	if(!url)
		url = "index.php";
		
	if(url.match(/^\?err=/)){
		var vars = getFromRequest(url);
		var msg = vars["err"];
		var obj = document.getElementById(vars["obj"]);
		alert(msg);
		obj.focus();
		obj.select();
		return;
	}
	
	location.href = url;
}
function getFromRequest(url){
	if(url.match(/\?/)){
		var get = url.substr(url.indexOf("?")+1);
		var items = get.split("&");
		var ret = Array();
		for(var i=0; i<items.length; i++){
			var varname = items[i].substr(0,items[i].indexOf("="));
			var varval  = items[i].substr(items[i].indexOf("=")+1);
			ret[varname] = varval;
		}
		return ret;
	}else{
		return false;
	}
}
function toggleOption(obj,option){
	var container = document.getElementById("container");
	if(!obj.className){
		obj.className = "checked";
		container.style.background = "url('gui/body_logo.png') no-repeat 97% 97%";
		setCookie("desktop_logo",1)
	}else{
		obj.className = "";
		container.style.background = "";
		setCookie("desktop_logo",0)
	}
}
function getCookie(name){
	var cook = document.cookie;
	var ret = null;
	var els = cook.split(";");
	for(i=0; i<els.length; i++){
		var tmp = els[i].split("=");
		var n = tmp[0];
		var v = tmp[1];
		if(n == name){
			ret = v;
			break;
		}
	}
	return ret;
}
function setCookie(name,value,days){
	if(!days)
		days = 30;
	var date = new Date();
	date.setTime(date.getTime() + (days*24*60*60*1000));
	var expires = date.toGMTString();
	document.cookie = name+"="+value+"; expires="+expires+"; path=/";
}
function ShowTab(showID,hideIDS){
	var obj = document.getElementById(showID);
	if(obj){obj.style.display="block";}
	for(var i=0; i<hideIDS.length; i++){
		obj=document.getElementById(hideIDS[i]);
		if(obj){obj.style.display="none";}
	}
}
function setCurrentTr(tr,attrname,attrval,head){
	var tbl = tr.parentNode;
	var trs = tbl.getElementsByTagName("tr");
	var start=head==true?1:0;
	for(var i=start; i<trs.length; i++){
		trs[i].setAttribute(attrname,"");
	}
	tr.setAttribute(attrname,attrval);
}
function setCurrentLi(a){
	var ul = a.parentNode.parentNode;
	var li = a.parentNode;
	var lis = ul.getElementsByTagName("li");
	for(i=0; i<lis.length; i++){
		if(lis[i] == li){
			lis[i].id="current";
			//alert("Current["+lis[i].id+"]: "+lis[i].childNodes[0].innerHTML);
		}else{
			lis[i].id="";
		}
	}
}
function setCurrentA(a){
	var ul = a.parentNode.parentNode;
	var li = a.parentNode;
	var lis = ul.getElementsByTagName("li");
	for(var i=0; i<lis.length; i++){
		var as = lis[i].getElementsByTagName("a");
		as = as[0];
		if(as == a){
			a.id = "current";
		}else{
			a.id="";
		}
	}
}
function getLabel(obj,id){
	var lbls = obj.getElementsByTagName("label");
	var ret=null;
	for(var i=0; i<lbls.length; i++){
		var fa = lbls[i].attributes['for'];
		if(fa && fa.value == id){
			ret = lbls[i];
			break;
		}
	}
	return ret;
}
function textareaMaxLength(txt){
	var val = txt.value.toString();
	var l = val.substr(0).length;
	var m = txt.getAttribute("maxlength");
	var lab = getLabel(txt.parentNode,txt.id);
	if(l>m){
		txt.value = val.substr(0,m);
		alert("Prekoračili ste ograničenje dužine za \""+ lab.innerHTML +"\" koje iznosi "+m+" karaktera.");
	}
}
function doTheRules(){
	//setRuleTitles();
	setInputRules();
	setTextareaRules();
}
// testing object over its id
function testElement1(id){
	var obj = document.getElementById(id);
	if(obj)
		return testElement2(obj);
}
// testing object over itself
function testElement2(obj){
	var val = obj.value;
	if(!val){
		val = obj.innerHTML;
	}
	if(!obj.attributes["rule"]){
		return true;
	}
	var rule = obj.attributes["rule"].value;
	if(rule.match(/^\//)){
		var tmp = rule.split('/');
		var rule = tmp[1];
		var flags = tmp[2];
	}else{
		var flags = "";
	}
	var reg = new RegExp(rule,flags);
	if(val.match(reg)){
		return true;
	}else{
		return false;
	}
}
function testAllElements(collection){
	var ret = new Object();
	ret.value=true;
	if(collection.length && collection.length>0){
		//alert(collection.length); return;
		for(x in collection){
			var _obj = collection[x];
			//alert(_obj);
			if(_obj.nodeName.match(/input|textarea|select/i)){
				//alert(_obj.nodeName+"#"+_obj.id);
				var rule = _obj.getAttribute("rule");
				var req = _obj.getAttribute("required");
				var flags="";
				
				if(req && trim(_obj.value).length==0){
					ret.value=false;
					ret.element=_obj;
					ret.errMsg = "";
					break;
				}
				
				if(rule && rule.match(/[^\s]+|[^\t]+|[^\n]+/)){
					if(rule.match(/^\//)){
						flags = rule.substr(rule.lastIndexOf("/")+1);
						rule = rule.substr(1,rule.lastIndexOf("/")-1);
					}
					
					var multi = _obj.getAttribute("type");
					multi = multi=="multiItem"?true:false;
					
					if(multi && !flags.match(/m/)){
						flags += "m";
					}
					
					var rgx = new RegExp(rule,flags);
					var val = _obj.value;
					if(!val.match(rgx)){
						//ypAjaxForm("<pre>"+rule+"\n"+flags+"\n"+val+"</pre>");
						ret.value=false;
						ret.element = _obj;
						break;
					}
				}
			}
		}
	}
	
	return ret;
}
function handleRegexError(obj,msg){
	if(!msg)
		msg = "Uneti podatak nije validan";
	imaGresaka(msg,obj);
}
function errorObject(code,element,elementName,elementId){
	//alert(code+" - "+element+" - "+elementName+" - "+elementId)
	this.code = code;
	this.element = element;
	this.elementName = elementName;
	this.elementID = elementId;
	
	var ima=false;
	for(var i=0; i<this.element.parentNode.childNodes.length; i++){
		if(this.element.parentNode.childNodes[i].id=="ErrorDiv"){
			ima = true;
			this.marker = this.element.parentNode.childNodes[i];
		}
	}
	if(!ima){
		var mark = document.createElement("div");
		mark.id = "ErrorDiv";
		mark.style.height = "17px";
		mark.style.display="none";
		mark.innerHTML = "<div id=\"ErrorText\">OVO POLJE NIJE VALIDNO!</div><img style=\"margin-left:5px;\" src=\"gui/arrow_error_down.gif\" />";
		var container = document.getElementById("container");
		var scrollLeft = container.scrollLeft;
		var scrollTop = container.scrollTop;	
		mark.style.left = this.element.offsetLeft-scrollLeft+"px";
		var padding = 4;
		mark.style.top = (this.element.offsetTop-parseInt(mark.style.height)-padding)-scrollTop+"px";
		this.element.parentNode.appendChild(mark);
		this.marker=mark;
	}
	
	this.setMarker = setErrorMarker;
	
	function setErrorMarker(value){
		this.marker.style.display="block"
		
		var errobj = this.element;
		errobj.ed = this.marker;
		errobj.onkeypress = errobj.onfocus = function(){
			if(this.ed){
				var par = this.parentNode;
				for(var i=0; i<par.childNodes.length; i++){
					if(par.childNodes[i] == this.ed){
						this.ed.style.display="none";
					}
				}
			}
		}
		var container = document.getElementById("container");
		if(typeof(container.onscroll) == "undefined"){
			container.onscroll = function(){
				var er = document.error;
				for(var i=0; i<er.length; i++){
					var scrollLeft = this.scrollLeft;
					var scrollTop = this.scrollTop;
					var mark = er[i].marker
					var el = er[i].element;
					mark.style.left = el.offsetLeft-scrollLeft+"px";
					var padding = 4;
					mark.style.top = (el.offsetTop-parseInt(mark.style.height)-padding)-scrollTop+"px";
				}
			}
		}
	}
}

function setInputRules(obj){
	if(!obj)obj=document;
	var inputs = obj.getElementsByTagName("input");
	document.error = Array();
	for(var i=0; i<inputs.length; i++){
		if(inputs[i].type=="text" && inputs[i].getAttribute("rule")){
			var inpt = inputs[i];
			inpt.onkeyup = function(){
				var t = testElement2(this);
				var err = new errorObject(1,this,this.name,this.id);
				if(!t){
					handleRegexError(this);
					if(inArray(document.error,err) === false)
						document.error.push(err);
					return;
				}else{
					imaGresaka("");
					var k = inArray(document.error,err);
					if(k !== false){
						document.error.splice(k,1);
					}
				}
			}
		}
	}
}
function setTextareaRules(obj){
	if(!obj)obj=document;
	var txts = obj.getElementsByTagName("textarea");
	document.error = Array();
	var l=0;
	out="";
	for(var i=0; i<txts.length; i++){
		//alert(txts[i].name)
		if(txts[i].getAttribute("rule")){
			var txt = txts[i];
			var type = txts[i].getAttribute("type");
			
			type = type?type:0;
			l++;
			if(type == "multiItem"){
				txt.onkeyup = function(e){
					var err = new errorObject(1,this,this.name,this.id);
					if(this.value.length){
						var lines = this.value.split("\n");
						var v = "";
						for(var i=0; i<lines.length; i++){
							if((lines[i] != "")){
								lines[i] = lines[i].replace(/^\s*/,"");
								lines[i] = lines[i].replace(/\s*$/,"");
								var rgx = new RegExp(this.getAttribute("rule"));
								if(!rgx.test(lines[i])){
									handleRegexError(this);
									if(inArray(document.error,err) === false){
										document.error.push(err);
									}
									return;
								}else{
									v += "\n"+lines[i];
									imaGresaka("");
									var k = inArray(document.error,err);
									if(k !== false){
										document.error.splice(k,1);
									}
								}
							}
						}
						if(e.keyCode == 13){
							v = v+"\n";
						}
						this.value = v.substr(1);
					}
				}
				out += l+". "+txt.name+" = "+txt.getAttribute("rule")+" - "+txt.onchange+"\n"
			}else{
				txt.onkeyup = function(){
					var err = new errorObject(1,this,this.name,this.id);
					//alert(this.name+"->"+err);
					var t = testElement2(this);
					if(!t){
						handleRegexError(this);
						if(inArray(document.error,err) === false){
							document.error.push(err);
						}
						return;
					}else{
						imaGresaka("");
						var k = inArray(document.error,err);
						if(k !== false){
							document.error.splice(k,1);
						}
					}
				}
			}
		}
	}
}
function testKeyEnter(func,e){
	if(!e){
		e = window.event;
	}
	var code;
	if(e.keyCode)
		code = e.keyCode;
	else if(e.which){
		code = e.which;
	}
	if(code == 13){
		eval(func);
	}
}
function showSelect(obj,url,func){
	document.body.onclick = function(){
		var fs = document.getElementById("floatingSelect");
		if(fs){
			fs.style.display="none";
		}
	}
	var sel = document.getElementById("floatingSelect");
	if(!sel){
		sel = createSelect(obj);
	}
	var container = document.getElementById("container");
	if(obj.value.length > 2){
		var scrTop = container.scrollTop;
		var scrLeft = container.scrollLeft;
		
		sel.style.top = (obj.offsetTop-scrTop)+obj.offsetHeight-1+"px";
		sel.style.left = (obj.offsetLeft-scrLeft)+"px";
		sel.style.minWidth = obj.offsetWidth-2+"px";
		
		container.object = obj;
		container.onscroll=function(e){
			var sel = document.getElementById("floatingSelect");
			var t = this.object.offsetTop+this.object.offsetHeight-1;
			sel.style.top = t-this.scrollTop+"px";
		}
		t = func;
		LoadRSDoc(url+"&v="+trim(obj.value),t);
	}else{
		sel.style.display="none";
	}
}
function updateFloatSelect(resource,to,toHidden){
	if(!resource){
		return;
	}
	/*alert(resource);
	alert(to);
	alert(toHidden);*/
	var sel = document.getElementById("floatingSelect");
	sel.style.display="block";
	var tmp = resource.split("\n");
	sel.innerHTML = "";
	for(i=0; i<tmp.length; i++){
		if(tmp[i].length){
			var tt = tmp[i].split(";");
			sel.innerHTML += "<li onmousedown=\"setValue(this,this.innerHTML,'"+to+"',this.value,'"+toHidden+"')\" value=\""+tt[0]+"\">"+tt[1]+"</li>";
		}
	}
	var selLis = sel.getElementsByTagName("li");
	for(var i=0; i<selLis.length; i++){
		selLis[i].style.minWidth = sel.style.minWidth;
	}
}
function setValue(obj,what,id,whatHidden,idHidden){
	var destObj = document.getElementById(id);
	var destObjHidden = document.getElementById(idHidden);
	
	if(destObj){				// novi naziv ulice
		destObj.value = what;
	}
	
	if(destObjHidden){			// nova sifra ulice
		destObjHidden.value = whatHidden;
	}
	
	obj.parentNode.style.display="none";
	document.body.onclick="";
}
function createSelect(obj){
	var container = document.getElementById("container");
	var el = document.createElement("ul");
	el.id = "floatingSelect";
	el.className = "floatingSelect";
	el.style.overflow = "auto";
	container.appendChild(el);
	return el;
}
function selectOption(obj,li){
	if(li.value>0){
		obj.value = li.value;
	}else{
		obj.value = li.innerHTML;
	}
	li.parentNode.style.display="none";
}
function ypconfirm(q,func,params,img,w){
	if(document.getElementById("yp_confirm"))
		return;
		
	if(typeof(w) == "undefined"){w=150}
	var ww = window.innerWidth;
	var wh = window.innerHeight;
	var cfrmHldr = document.createElement("div");
	cfrmHldr.id = "yp_confirm";
	cfrmHldr.style.width = w+"px";
	cfrmHldr.onmousedown = function(e){
		if(e.target.type != "button"){
			this.move=true;
			this.diffX = e.clientX-this.offsetLeft;
			this.diffY = e.clientY-this.offsetTop;
		}
		return false;
	}
	cfrmHldr.onclick = function(){return false;}
	cfrmHldr.onmouseup = function(){this.move=false;return true;}
	cfrmHldr.onmouseout = function(){this.move=false;}
	cfrmHldr.onmousemove = function(e){
		if(this.move){
			this.style.left = (e.clientX-this.diffX)+"px";
			this.style.top = (e.clientY-this.diffY)+"px";
		}
	}
	var btnNO = document.createElement("input");
	btnNO.type = "button";
	btnNO.value = "Ne";
	btnNO.onclick = function(){
		document.body.removeChild(this.parentNode);
		return 0;
	}
	var btnYES = document.createElement("input");
	btnYES.type = "button";
	btnYES.value = "Da";
	btnYES.response = params;
	btnYES.onclick = function(){
		eval(func+"(this)");
		document.body.removeChild(this.parentNode);
	}
	var content = document.createElement("div");
	content.className = "content";
	content.innerHTML = q;
	
	cfrmHldr.appendChild(content);
	cfrmHldr.appendChild(btnYES);
	cfrmHldr.appendChild(btnNO);
	document.body.appendChild(cfrmHldr);
	
	cfrmHldr.style.left = Math.round((ww-cfrmHldr.offsetWidth)/2)+"px";
	cfrmHldr.style.top = Math.round((wh-cfrmHldr.offsetHeight)/2)+"px";
}
function ypalert(title,msg){
	var darker = getDarkerObject();
	var content = document.createElement("div");
	var closeBtn = document.createElement("input");
	var w = window.innerWidth;
	var h = window.innerHeight;
	
	document.body.appendChild(darker);
	document.body.appendChild(content);
	
	
	
	content.id = "ypAlert";
	content.innerHTML = "<h1>"+title+"</h1>"+"<div>"+msg+"</div>";
	content.style.position = "absolute";
	content.style.maxWidth = "640px";
	content.style.maxHeight = "480px";
	content.style.overflow = "auto";
	content.className = "area";
	content.style.left = Math.round((w-content.offsetWidth)/2)+"px";
	content.style.top = Math.round((h-content.offsetHeight)/2)+"px";
	
	closeBtn.value = "OK";
	closeBtn.type = "button";
	closeBtn.style.width = "60px";
	closeBtn.onclick = function(){
		var d = document.getElementById("darker");
		var a = document.getElementById("ypAlert");
		a.parentNode.removeChild(a);
		d.parentNode.removeChild(d);
	}
	content.appendChild(closeBtn);
	closeBtn.style.marginLeft = Math.round((closeBtn.parentNode.offsetWidth-closeBtn.offsetWidth)/2)+"px"
}
function getDarkerObject(){
	var dark = document.createElement("div")
	dark.id = "darker";
	dark.innerHTML = "&nbsp;"
	dark.style.top = "0px";
	dark.style.left = "0px";
	dark.style.width = window.innerWidth+"px";
	dark.style.height = window.innerHeight+"px";
	
	return dark;
}
function duplicateObject(tagname,holder){
	var elems = holder.getElementsByTagName(tagname);
	var lastElem = elems[elems.length-1];
	var newElem = lastElem.cloneNode(true);
	if(newElem.id != null)
		newElem.id = parseInt(newElem.id)+1;
	var objs = Array("input","select","textarea");
	for(var i=0; i<objs.length; i++){
		var els = newElem.getElementsByTagName(objs[i]);
		for(var j=0; j<els.length; j++){
			if(els[j].name){
				var indx = els[j].name.indexOf("_");
				els[j].name = (parseInt(els[j].name.substr(0,indx))+1)+"_"+els[j].name.substr(indx+1);
			}
		}
	}
	holder.appendChild(newElem);
}
function duplicateObject1(obj,holder){
	var newElem = obj.cloneNode(true);
	var increment = getIncrement(obj.id);
	var base = increment["base"];
	var num = increment["extension"];
	newElem.id = base +"_"+(num+1);
	var objs = Array("input","select","textarea","label");
	for(var i=0; i<objs.length; i++){
		var els = newElem.getElementsByTagName(objs[i]);
		for(var j=0; j<els.length; j++){
			if((els[j].nodeName.toLowerCase() != "label")){
				var nm = els[j].getAttribute("name");
				if(nm){
					var t = getIncrement(els[j].name);
					var b = t["base"];
					var e = parseInt(t["extension"]);
					els[j].name = b+"_"+(e+1);
					els[j].id = b+"_"+(e+1);
				}
			}else{
				var f = els[j].getAttribute("for")
				if(f){
					var t = getIncrement(f);
					var b = t["base"];
					var e = t["extension"];
					els[j].setAttribute("for",b+"_"+(e+1));
				}
			}
		}
	}
	holder.appendChild(newElem);
	setInputRules();
	setTextareaRules();
	return newElem;
}
function getIncrement(str){
	var ret = Array();
	ret["base"] = str.substr(0,str.lastIndexOf("_"));
	ret["extension"] = parseInt(str.substr(str.lastIndexOf("_")+1));
	return ret;
}
function disableTextSelect(id){
	obj = document.getElementById(id)
	if(obj){
		obj.onmousedown = function(){return false;}
	}
}
function setCurrentLetterFilter(filter){
	var uls = document.getElementsByTagName("ul");
	for(var i=0; i<uls.length; i++){
		if(uls[i].className == "letter_filter"){
			var lis = uls[i].getElementsByTagName("li");
			for(var j=0; j<lis.length; j++){
				if(filter.length){
					var a = lis[j].getElementsByTagName("a");
					if(a.length){
						a = a[0];
						val = a.innerHTML.toLowerCase();
						if(val == filter){
							a.id = "current";
						}else{
							a.id = "";
						}
					}
				}else{
					var a = lis[j].getElementsByTagName("a");
					a = a[0];
					val = a.innerHTML.toLowerCase();
					if(j==0){
						a.id = "current";
					}else{
						a.id = "";
					}
				}
			}
			break;
		}
	}
}
function setRuleTitles(){
	var inpts = document.getElementsByTagName("input");
	if(inpts.length){
		for(var i=0; i<inpts.length; i++){
			if(inpts[i].getAttribute("maxlength")){
				if(inpts[i].title.length)
					inpts[i].title += "    "
				inpts[i].title += "Max karaktera: "+inpts[i].getAttribute("maxlength");
			}
		}
	}
}
function ypAjaxForm(html,type){
	if(!type){
		type=1;
	}
	switch(type){
		case 1:
			ypAjaxFormFirst(html);
			break;
		case 2:
			ypAjaxFormSecond(html);
			break;
	}
}
function ypAjaxFormFirst(html){
	var hldr = document.getElementById("container");
	var w = window.innerWidth;
	var h = window.innerHeight;
	
	var dark = getDarkerObject()//document.createElement("div");
	var main = document.createElement("div");
	main.style.visibility = "hidden";
	main.style.maxHeight=(h>300)?(h-100)+"px":"300px";
	var closeBtn = document.createElement("a");
	document.body.appendChild(dark);
	document.body.appendChild(main);
	
	closeBtn.innerHTML = '<img src="gui/close_12.gif" border="0" />';
	closeBtn.href = "javascript:closeYpAjaxForm()";
	closeBtn.style.position = "absolute";
	closeBtn.style.margin = "1px 0px 0px -14px";
	closeBtn.title="Close";
	
	main.appendChild(closeBtn);
	
	main.id = "mainYPAjax";
	main.innerHTML += html;
	
	var inpts = main.getElementsByTagName("input");
	var lis = main.getElementsByTagName("li");
	var closeBtn = main.childNodes[0];
	var focusobj=null;
	
	if(inpts.length){
		focusobj = inpts[0];
	}else if(lis.length){
		var a = lis[0].getElementsByTagName("a");
		if(a.length){
			a = a[0];
			focusobj = a;
		}else{
			focusobj = closeBtn;
		}
	}else{
		focusobj = closeBtn
	}
	focusobj.focus();
	focusobj.onkeypress = function(e){
		if(e.keyCode == 27){
			if(closeBtn.onclick){
				closeBtn.click();
			}else{
				eval(closeBtn.href);
			}
		}
	}
	main.style.left = Math.round((w-main.offsetWidth)/2)+"px";
	main.style.top = Math.round((h-main.offsetHeight)/2)+"px";
	main.style.visibility = "visible";
	main.onkeypress = function(e){
		//window.status = e.keyCode+"-"+String.fromCharCode(e.keyCode);
		if(e.keyCode == 27){
			closeYpAjaxForm();
		}
	}
}
function ypAjaxFormSecond(html){
	var hldr = document.getElementById("container");
	var w = window.innerWidth;
	var h = window.innerHeight;
	
	var main = document.createElement("div");
	main.style.visibility = "hidden";
	var closeBtn = document.createElement("a");
	document.body.appendChild(main);
	
	closeBtn.innerHTML = '<img src="gui/close_12.gif" border="0" />';
	closeBtn.href = "javascript:closeYpAjaxForm(2)";
	closeBtn.style.position = "absolute";
	closeBtn.style.margin = "1px 0px 0px -14px";
	closeBtn.title="Close";
	
	main.appendChild(closeBtn);
	
	main.id = "mainYPAjax1";
	main.innerHTML += html;
	
	var inpts = main.getElementsByTagName("input");
	var lis = main.getElementsByTagName("li");
	var closeBtn = main.childNodes[0];
	var focusobj=null;
	if(inpts.length){
		focusobj = inpts[0];
	}else if(lis.length){
		var a = lis[0].getElementsByTagName("a");
		a = a[0];
		focusobj = a;
	}else{
		focusobj = closeBtn
	}
	focusobj.focus();
	focusobj.onkeypress = function(e){
		if(e.keyCode == 27){
			if(closeBtn.onclick){
				closeBtn.click();
			}else{
				eval(closeBtn.href);
			}
		}
	}
	main.style.left = Math.round((w-main.offsetWidth)/2)+"px";
	main.style.top = Math.round((h-main.offsetHeight)/2)+"px";
	main.style.visibility = "visible";
	main.onkeypress = function(e){
		if(e.keyCode == 27){
			closeYpAjaxForm(2);
		}
	}
}
function closeYpAjaxForm(type){
	var darker	= document.getElementById("darker");
	var main	= document.getElementById("mainYPAjax");
	var main1	= document.getElementById("mainYPAjax1")
	if(darker){
		if(!type){
			type=1;
		}
		switch(type){
			case 1:
				document.body.removeChild(darker);
				document.body.removeChild(main);
				break;
			case 2:
				document.body.removeChild(main1);
		}
	}
}
function updateYpAjaxFormList(html,kword){
	var sl = document.getElementById("searchList");
	if(sl){
		var hldr = sl.parentNode;
		var forma = hldr.getElementsByTagName("form");
		forma = forma[0];
		var input = forma.getElementsByTagName("input");
		for(x in input){
			if(input[x].type=="text"){
				input = input[x];
				break;
			}
		}
		input.value = kword;
		hldr.removeChild(sl);
		hldr.innerHTML += html;
	}else{
		alert("Nema liste!");
	}
}
function ypTooltip(html,obj,left,top){
	var tt = document.getElementById("YPtolltip");
	if(tt){
		ypTooltipHide();
	}
	var div = document.createElement("div");
	div.id="YPtooltip";
	div.innerHTML = html;
	obj.parentNode.appendChild(div);
	//alert(obj.offsetLeft)
	div.style.left	= left>0?left+"px":(obj.offsetLeft-div.offsetWidth-2)+"px";
	div.style.top	= top>0?top+"px":(obj.offsetTop)+"px";
	//alert(obj.parentNode);
	
	obj.onmouseout = function(){
		ypTooltipHide();
	}
}
function ypTooltipHide(){
	var tt = document.getElementById("YPtooltip");
	if(tt){
		tt.parentNode.removeChild(tt);
	}
}

function searchUlice(obj,destObj,destObjHidden,type,lnGrad,lnLops,lnNas){
	if(!type){
		type=1;
	}
	var defaultText="";
	var dobj = document.getElementById(destObj);
	if(dobj){
		defaultText = trim(dobj.value)
	}
	var ul = prompt("Naziv ulice: ",defaultText);
	if(ul){
		LoadRSDoc('adrese.php?a=searchUlica&ul='+ul+'&d='+destObj+'&dh='+destObjHidden+"&st="+type+"&lnGrad="+lnGrad+"&lnLops="+lnLops+"&lnNas="+lnNas,'ypAjaxForm('+type+')');
	}
}
function promeniUlicu(dh,ul_id,d,ul_ime,btn){
	var destObj = document.getElementById(d);
	var lokobjnames = trim(btn.getAttribute("lokacijeObjects"));
	if(lokobjnames.length>0){
		lokobjnames = lokobjnames.split(/;/g);
		var lid = parseInt(trim(btn.getAttribute("lokacijaID")));
		var ltype = parseInt(trim(btn.getAttribute("lokacijaType")));
		if(ltype>0 && lid>0){
			var _lokObj=null;
			var _lokObjType=null;
			switch(ltype){
				case 1:
					_lokObj = document.getElementById(lokobjnames[0]);
					_lokObjType="grad";
					break;
				case 2:
					_lokObj = document.getElementById(lokobjnames[1]);
					_lokObjType="lok_opstina";
					break;
				case 3:
					_lokObj = document.getElementById(lokobjnames[2]);
					_lokObjType="naselje";
					break;
			}
			if(_lokObj!=null){
				var opts = _lokObj.options
				for(var i=0; i<opts.length; i++){
					if(opts[i].getAttribute("value")==lid){
						opts[i].selected = true;
					}else{
						opts[i].slected = false;
					}
				}
				updateSelectsAdresa(_lokObj,_lokObjType);
			}
		}
	}
	destObj.value = ul_ime;
	var destObjHidden = document.getElementById(dh);
	destObjHidden.value = ul_id;
}
function inArray(stack,needle){
	var ret = false;
	var tip = typeof(needle);
	if(tip.toLowerCase() == "object"){
		var test = implode1("",needle);
		for(var i=0; i<stack.length; i++){
			var test1 = implode1("",stack[i]);
			if(test == test1){
				ret = i;
				break;
			}
		}
	}else{
		for(var i=0; i<stack.length; i++){
			if(stack[i] == needle){
				ret = i;
				break;
			}
		}
	}
	return ret;
}
function implode1(glue,stack){
	var ret = "";
	if(typeof(stack) == "object"){
		for(x in stack){
			ret += stack[x]+glue;
		}
		if(glue.length)
			ret = ret.substr(0,ret.length-glue.length);
	}
	return ret;
}
function removeEmptyItems(obj){
	if(typeof(obj) == "object"){
		var tmp = Array();
		for(x in obj){
			//alert(x+": "+obj[x]+"\t"+typeof(obj[x])+","+obj[x].length);
			if(obj[x].length==0 && typeof(obj[x])=="string"){
				//delete obj[x];
			}else{
				tmp.push(obj[x]);
			}
		}
		obj=tmp;
	}
	return obj;
}
function getElementsByClassName(parent,className){
	var ret=Array();
	for(var i=0; i<parent.childNodes.length; i++){
		if(parent.childNodes[i].className && parent.childNodes[i].className==className){
			ret.push(parent.childNodes[i])
		}
	}
	if(ret.length){
		return ret;
	}else{
		return false;
	}
}
function strip_number_format(str){
	str = str.replace(/\./g,"");
	str = str.replace(/,/,".");
	return str;
}
function number_format(a, b, c, d) {
	// number_format(number, decimals, comma, formatSeparator)
	if(typeof(c)=="undefined"){	c = ","}
	if(typeof(d)=="undefined"){	d = "."}
	a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
	e = a + '';
	f = e.split('.');
	if(!f[0]) f[0] = '0';
	if(!f[1]) f[1] = '';
	if(f[1].length < b){
		g = f[1];
		for(i = f[1].length + 1; i <= b; i++) {
			g += '0';
		}
		f[1] = g;
	}
	if(d != '' && f[0].length > 3) {
		h = f[0];
		f[0] = '';
		for(j = 3; j < h.length; j += 3) {
			i = h.slice(h.length - j, h.length - j + 3);
			f[0] = d + i +  f[0] + '';
		}
		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
		f[0] = j + f[0];
	}
	c = (b <= 0) ? '': c;
	return f[0] + c + f[1];
}

//---------------------------------------------
indikator_greske=0;

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  var obj;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); obj= val;
    if (val) {  nm=val.name; nt=val.title; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+((nt!="")? ('"'+nt+'"'):nm)+' mora sadržati e-mail adresu.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+((nt!="")? ('"'+nt+'"'):nm)+' mora biti broj.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+((nt!="")? ('"'+nt+'"'):nm)+' mora biti broj između '+min+' i '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+((nt!="")? ('"'+nt+'"'):nm)+' je zahtevano polje.\n'; }
  } if (errors) alert('Moguće su sledeće greške:\n'+errors);
  document.MM_returnValue = (errors == '');
  //alert( document.MM_returnValue);
  if(document.MM_returnValue) indikator_greske=0;
  else indikator_greske=1;
  
  obj.focus();
  //obj.style.backgroundColor = "red";
  obj.select();
}

function testDelatnosti(ul){
	var lis = ul.getElementsByTagName("li");
	var out;
	var i, j;
	
	out = "Delatnosti:\n";
	for(i=0; i<lis.length; i++){
		out += (i+1)+". "+lis[i].id+"\n";
	}
	alert(out);
	
	var dd = document.getElementById("komitent_delatnosti_data");
	var b  = dd.getElementsByTagName("blockquote");
	out = "blockquotas:\n";
	for(i=0; i<b.length; i++){
		out += (i+1)+". "+b[i].id+", delid="+b[i].getAttribute("delid")+"\n";
	}
	alert(out);
}
function showContextMenu(e,obj,contentFunc){
	var c = document.getElementById("contextMenu");
	if(c){
		c.parentNode.removeChild(c);
	}
	var sadrzaj = eval(contentFunc);
	var cm = document.createElement("div");
	var nn = obj.nodeName;
	var nns = obj.parentNode.getElementsByTagName(nn);
	for(var i=0; i<nns.length; i++){
		if(nns[i].id = "dblclicked"){
			nns[i].id = "";
		}
	}
	obj.id = "dblclicked";
	
	cm.id = "contextMenu";
	cm.innerHTML = sadrzaj;
	cm.style.left = e.pageX+"px";
	cm.style.top = e.pageY+"px";
	
	obj.onmousedown = function(){return false;}
	obj.onmouseup = function(){return true;}
	
	document.body.dblclickedelement = obj
	document.body.onclick = function(){
		var c = document.getElementById("contextMenu");
		this.dblclickedelement.id = "";
		if(c)
		this.removeChild(c);
	}
	
	document.body.appendChild(cm);
}
function incrementNumStep(id){
	var obj;
	if(typeof(id)=="string"){
		obj = document.getElementById(id);
	}else{
		obj = id;
	}
	var maxval = obj.getAttribute("maxval");
	var val = parseInt(obj.value);
	if(!maxval || maxval>val){
		obj.value = val+1;
	}
}
function decrementNumStep(id){
	var obj;
	if(typeof(id)=="string"){
		obj = document.getElementById(id);
	}else{
		obj = id;
	}
	var minval = obj.getAttribute("minval");
	var val = parseInt(obj.value);
	if(!minval || minval<val){
		obj.value = val-1;
	}
}
function toNumber(str){
	num = str.replace(/[^\d]/g,"");
	if(num.length){
		return num;
	}else{
		return "0";
	}
}
function PromeniTipPolja(obj,newNodeName){
	obj.nodeName = newNodeName;
}
function odstampaj(html){
	var c = html;
	if(newWin){
		mewWin.close();
	}
	var newWin = window.open("","printWIN","");
	newWin.document.write(c);
	newWin.focus();
	//newWin.stop();
}
function print_r(obj){
	var out="";
	for(x in obj){
		out += x+": ";
		var t = typeof(obj[x]);
		if(t.toLowerCase() == "object"){
			out += "\n";
			for(y in obj[x]){
				out += "\t\t"+y+": "+obj[x][y]+"\n";
			}
		}else{
			out += " "+obj[x];
		}
		out += "\n";
	}
	alert(out);
}
function exportCSV(node,a){
	if(node.nodeName && (node.nodeName.toLowerCase()=="table")){
		html = node.innerHTML;
		//html = escape(html);
	}else{
		html=node;
	}
	
	var tarea = document.createElement('textarea');
		tarea.innerHTML = html.replace(/&nbsp;/g," ");
		html = tarea.value;
	action  = "a="+a;
	action += "&html="+escape(html);
	switch(a){
		case 'default':
			f = "afterExport(1)";
			break;
		default:
			f = "afterExport(0)";
			break;
	}
	LoadRSDoc("exportcsv.php",f,action,"",1);
}
function afterExport(response,fixlatin){
	var file, filename;
	if(response.match(/\{!\}/)){
		var tmp = response.split(/\{!\}/);
		file		= tmp[0];
		filename	= tmp[1];
	}else{
		file=response;
		filename="export.xls";
	}
	//alert(response);
	html = '<div class="area">';
	//html += '<p class="download">tst</p>';
	html += '<a class="download" href="down.php/?f='+file+'&fn='+filename+'" target="_blank" onclick="closeYpAjaxForm()">preuzmite fajl</a>';
	html += '</div>';
	ypAjaxForm(html);
}
function submitForm(forma,script,method,responseFunc,escaped,send){
	if(!method.match(/^post$/i)){
		method="get";
	}
	if(!escaped){
		escaped=0;
	}
	var els = forma.elements;
	var action = "";
	
	for(var i=0; i<els.length; i++){
		var name = trim(els[i].name);
		var val  = trim(els[i].value);
		var skip=false;
		if( !(typeof(name) == 'undefined') && !(typeof(val) == 'undefined')){
			if(name.length){
				if(els[i].type.match(/^checkbox$|^radio$/i)){
					if(els[i].checked){
						val = els[i].value;
						skip=false;
					}else{
						skip=true;
					}
				}
				if(escaped){
					val = _escape(val);
				}
				if(els[i].type.match(/file/i)){
					val = encodeURI(val);
				}
				if(!skip){
					action += "&"+name+"="+val;
				}
			}
		}
	}
	action = action.substr(1);
	//alert(script+"\n"+action+"\n"+responseFunc+"\n"+send)
	if(method.toLowerCase() == 'post'){
		if(send==1){
			LoadRSDoc(script,responseFunc,action,3,"POST");
		}else{
			LoadRSDoc(script,responseFunc,action,"",1);
		}
	}else{
		LoadRSDoc(script+"?"+action,responseFunc);
	}
}
function previewImage(obj){
	if(obj.value.length){
		var homedir = "http://server.yellow/yp/";
		var pre = obj.getAttribute("pre");
		var html = '<div class="area">';
		var src = homedir+trim(pre)+obj.value;
		window.status = src;
		html += '<img src="'+src+'" />';
		html += '</div>';
		ypAjaxForm(html);
	}
}
function debug1(obj){
	var out="";
	for(x in obj){
		out += x+"["+typeof[x]+"]: "+obj[x]+"<br /><br />";
	}
	ypAjaxForm(out);
}

function utf2yuscii(str,rev){
	rev = rev>0?true:false;
	
	var utf = Array("ž","Ž","č","Č","š","Š","ć","Ć","đ","Đ");
	var yuscii = Array("`","@","~","^","{","[","}","]","|","\\");
	var rgxp, repl;
	for(var i=0; i<utf.length; i++){
		if(rev){
			rgxp = new RegExp("\\"+yuscii[i],"g");
			repl = utf[i];
		}else{
			rgxp = new RegExp(utf[i],"g");
			repl = yuscii[i];
		}
		str = str.replace(rgxp,repl);
	}
	return str;
}
function PageFilter(lnk,script,page){
	var fq = "page="+page+"&"+lnk.parentNode.parentNode.getAttribute("filterquery");
	LoadRSDoc(script,'setContent',fq,"",1);
}